package com.ry.est.service.impl;

import com.ry.est.constants.Constants;
import com.ry.est.dao.MalfunctionOptionsDao;
import com.ry.est.dto.MalfunctionOptionsDTO;
import com.ry.est.entity.MalfunctionOptions;
import com.ry.est.service.MalfunctionOptionsService;
import com.ry.est.util.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 故障选项组件
 * @author ry
 * @since 2021-11-09 08:42
 **/
@Service
public class MalfunctionOptionsServiceImpl implements MalfunctionOptionsService {
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private MalfunctionOptionsDao malfunctionOptionsDao;

    @Override
    public List<MalfunctionOptionsDTO> listByMalfId(Long malfId) {
        List<MalfunctionOptions> malfunctionOptions = malfunctionOptionsDao
                .listByMalfId(malfId, Constants.EST_NOT);


        List<MalfunctionOptionsDTO> optionsDTOS = malfunctionOptions
                .stream()
                .map(entity -> {
            MalfunctionOptionsDTO malfunctionOptionsDTO = new MalfunctionOptionsDTO();
            malfunctionOptionsDTO.setId(entity.getId());
            malfunctionOptionsDTO.setOptionName(entity.getOptionName());
            malfunctionOptionsDTO.setIsHint(entity.getIsHint());
            malfunctionOptionsDTO.setHintInfo(entity.getHintInfo());
            malfunctionOptionsDTO.setHintImg(entity.getHintImg());
            malfunctionOptionsDTO.setProcessType(entity.getProcessType());
            malfunctionOptionsDTO.setRatio(entity.getRatio());

            return malfunctionOptionsDTO;
        }).collect(Collectors.toList());


        return optionsDTOS;
    }

    @Override
    public List<MalfunctionOptionsDTO> listByIds(List<Long> ids) {
        List<MalfunctionOptions> malfunctionOptions = malfunctionOptionsDao.listByIds(ids);
        List<MalfunctionOptionsDTO> malfunctionOptionsDTOS = BeanUtils.convertToDTOList(malfunctionOptions, MalfunctionOptionsDTO.class);

        return malfunctionOptionsDTOS;
    }
}
